package thread;

public class Demo15 {

    private static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 500; i++) {
                count++;
            }
            System.out.println("t1 end");
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 500; i++) {
                count++;
            }
            System.out.println("t2 end");
        });

//        t1.start();
//        t2.start();
//
////        System.out.println("count:" + count);// 0
//
//        t1.join();
//        t2.join();
//
//        System.out.println("count:" + count);//实际与预期不符合，bug（线程不安全）由多线程并发执行引起

        t1.start();
        t1.join();

        t2.start();
        t2.join();
        System.out.println("count:" + count);//串行执行，结果与预期相符合

    }
}
